<template>
  <div class="app-container">
    <h4 class="form-header h4">答题信息</h4>
    <el-table v-loading="loading"   border :data="answerList">
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{(pageNum - 1) * pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="题目" align="center" prop="question"    :show-overflow-tooltip="true" />
      <el-table-column label="答案选项" align="center" prop="options"  :show-overflow-tooltip="true" />
      <el-table-column label="正确答案" align="center" prop="answer" />
      <el-table-column label="我的答案" align="center" prop="myAnswer" />
      <el-table-column label="得分" align="center" prop="score" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getScoreDetails } from "@/api/business/exam";

export default {
  name: "ScoreDetail",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 分页信息
      total: 0,
      pageNum: 1,
      pageSize: 10,
      // 选中角色编号
      roleIds: [],
      // 角色信息
      roles: [],
      answerList: [],
      // 用户信息
      form: {},
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        testName: undefined
      }
    };
  },
  created() {
    const userId = this.$route.params && this.$route.params.userId;
    const testName = this.$route.params && this.$route.params.testName;
    this.queryParams.userId = userId;
    this.queryParams.testName = testName;
    if (userId && testName) {
      this.loading = true;
      getScoreDetails(this.queryParams)
        .then(response => {
          this.answerList = response.data.rows;
          this.total = response.data.total;
          this.loading = false;
        })
        .catch(err => {
          this.loading = false;
        });
    }
  },
  methods: {
    getList() {
      this.loading = true;
      getScoreDetails(this.queryParams)
        .then(response => {
          this.answerList = response.data.rows;
          console.log(response.data.total);
          this.total = response.data.total;
          this.loading = false;
        })
        .catch(err => {
          this.loading = false;
        });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.roleIds = selection.map(item => item.roleId);
    },
    // 保存选中的数据编号
    getRowKey(row) {
      return row.roleId;
    },
    /** 提交按钮 */
    submitForm() {
      const examId = this.form.id;
      const roleIds = this.roleIds.join(",");
      updateExamRole({ examId: examId, roleIds: roleIds }).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.close();
      });
    },
    /** 关闭按钮 */
    close() {
      const obj = { path: "/tag/examConfig" };
      this.$tab.closeOpenPage(obj);
    }
  }
};
</script>